﻿using System;
using System.Data.SqlClient;
using Ext.Net;

namespace Hybrid
{
    public class DBConnection
    {
        private static System.Configuration.ConnectionStringSettings connString;
        public static SqlConnection Open()
        {
            SqlConnection sqc=null;
            System.Configuration.Configuration rootWebConfig =
            System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("/MyWebSiteRoot");
            if (rootWebConfig.ConnectionStrings.ConnectionStrings.Count > 0)
            {
                connString = rootWebConfig.ConnectionStrings.ConnectionStrings["DBConnectionString"];
                if (connString != null)
                {
                    sqc = (new SqlConnection(connString.ConnectionString));
                    try
                    {
                        sqc.Open();
                    }
                    catch (Exception ex)
                    {
                        X.Msg.Notify("Connection Error", ex.Message + @"<br />" + ex.HelpLink).Show();
                    }
                    
                }
            }
            return (sqc);
        }
    }
}